<?php
/**
 * Created by JetBrains PhpStorm.
 * User: romanches
 * Date: 28.10.11
 * Time: 12:09
 * To change this template use File | Settings | File Templates.
 */
 
class DateUtil {

    public static function formatDateToDatabase($str){
        if($str){
            $ar = explode('.',$str);

            $day = $ar[0];
            $month = $ar[1];
            $year = $ar[2];

            if(!checkdate($month,$day,$year)) return false;
            return $year.'-'.$month.'-'.$day;
        }
        return false;
    }

    public static function formatDateToDisplay($str){
        if($str){
            $ar = explode('-',$str);
            if(count($ar) == 3){
                $day = $ar[2];
                $month = $ar[1];
                $year = $ar[0];

                return $day.'.'.$month.'.'.$year;
            }else{
                return $str;
            }
        }
        return false;
    }

}
